<h2 style="text-align: center;">
	ECE 264 Individual Assignment 2<br></h2><h2 style="text-align: center;">Makefile and Pointers<br></h2><font size="+2"><span style="font-weight: bold;">Makefile</span></font><br><br>It is impossible to write a C program using a single file. When you
include a header file, you are already using multiple files.You do not
implement printf, do you? Where does it come from? It comes from C
libraries, /usr/lib/libc.so. Why is C designed in this
way?&nbsp; What are the advantages of writing a program using multiple files?
<ul><li> Reduce redundant work.&nbsp; Many frequently used functions are
supported by libraries. You don't have to write your own printf, scanf,
or fopen.</li><li>
Improve portability. Some functions handle low-level activities related
to hardware, such as reading files from a disk or sending packets
through a network. It is better to isolate the hardware-specific in
libraries so that your program can run on different computers, as long
as your program uses the correct libraries (usually need to recompile
the source code).</li><li>
		Enhance performance. Libraries are well optimized so your program can have better performance.</li><li>
Partition work for collabortion. When you write a large program with
other people, it is natural to break the work into smaller units. Each
of you is responsibile for some units. Each unit is stored in a single
file.</li><li>
Save compilation time. Compiling a large program can take hours. If the
whole program is in a single file and you change only one line, you
have to wait for hours to check whether your change is correct. A
better solution is to break the program into many files and compile
only the files affected by your change. Then the object files are
linked. This may take a few seconds, much better than a few hours.&nbsp;</li></ul>
<p>
	The last advantage is critical in developing large programs. This is an important reason to separate compilation from linking.</p><p>Suppose you have a program that requires four .c files: file1.c, file2.c, file3.c, and file4.c. You can compile them separately.</p><p style="font-family: Courier New,Courier,monospace;">gcc -Wall -Wshadow -c file1.c<br>gcc -Wall -Wshadow -c file2.c<br>gcc -Wall -Wshadow -c file3.c<br>gcc -Wall -Wshadow -c file4.c</p><p>
	You should always have</p>
<pre style="font-family: Courier New,Courier,monospace;"> -Wall -Wshadow <br></pre>
<p>
	after gcc. They will give you warning messages that likely come from errors. Each of these commands tells gcc to convert a .c file to an intermediate format called an object file (.o). Notice <span style="font-family: Courier New,Courier,monospace;">-c</span> after gcc. The four commands will create file1.o, file2.o, file3.o, and file4.o respectively. An object file is not ready for the computer to run yet. You need to link the object files and create an executable file (i.e. the program)</p><span style="font-family: Courier New,Courier,monospace;">gcc -Wall -Wshadow file1.o file2.o file3.o file4.o -o program</span><br><p>Without <span style="font-family: Courier New,Courier,monospace;">-c</span>, gcc will create the executable. The name is given after <span style="font-family: Courier New,Courier,monospace;">-o</span>.&nbsp;</p><p>To take advantage of using multiple files, you need to keep track which files have been modified. For example, if you modify only file2.c, you want to update file2.o without recreating file1.o, file3.o, file4.o. More specifically, if you change only file1.c, you should run only the following two commands</p><span style="font-family: Courier New,Courier,monospace;">gcc -Wall -Wshadow -c file2.c<br>gcc -Wall -Wshadow file1.o file2.o file3.o file4.o -o program</span><br><p>This can save time because we do not need to run the other commands.</p><p>The advantage comes at a cost: we need to keep track which files have been changes. This is too much work for software developers so a tool is available to do this work. It is the <span style="font-family: Courier New,Courier,monospace;">make</span> command in Linux. To execute <span style="font-family: Courier New,Courier,monospace;">make</span>, we need to give an input file that tells the <span style="font-family: Courier New,Courier,monospace;">make</span> command what to do.</p><p style="font-family: Courier New,Courier,monospace;">make -f input</p><p>If we do not provide the name of the input file, <span style="font-family: Courier New,Courier,monospace;">make</span> assumes the name is <span style="font-family: Courier New,Courier,monospace;">Makefile</span>. In other words, the following two commands are the same</p><span style="font-family: Courier New,Courier,monospace;">make -f Makefile</span><br style="font-family: Courier New,Courier,monospace;"><span style="font-family: Courier New,Courier,monospace;">make</span><br><p>What is in Makefile?&nbsp; Makefile contains a set of groups. Each group has the following format:</p><p style="font-family: Courier New,Courier,monospace;">target: dependence # separated by :<br>&nbsp;&nbsp;&nbsp; actions&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # actions must be after TAB<br></p><p>In <span style="font-family: Courier New,Courier,monospace;">Makefile</span>, anything after<span style="font-family: Courier New,Courier,monospace;"> #</span> is a comment. Please notice that this is different from C programs. C programs use /* ... */ to enclose commands.<br></p>Let's use <br><p><br></p><p><br></p><p><br></p><p><br></p>